/*
 * @Author: szx
 * @Date: 2021-11-08 13:26:36
 * @LastEditTime: 2021-11-08 13:33:40
 * @Description:
 * @FilePath: \leetcode\700-799\700\700.cpp
 */
#include <iostream>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right)
        : val(x), left(left), right(right) {}
};

class Solution {
   public:
    TreeNode *searchBST(TreeNode *root, int val) {
        if (root) {
            if (root->val == val)
                return root;
            else if (root->val > val)
                return searchBST(root->left, val);
            else
                return searchBST(root->right, val);
        }
        return nullptr;
    }
};

class Solution {
   public:
    TreeNode *searchBST(TreeNode *root, int val) {
        while (root && root->val != val) {
            root = val < root->val ? root->left : root->right;
        }
        return root;
    }
};
int main() { return 0; }